package com.graduation.adminservice.controller;

import com.graduation.pojo.po.Category;
import com.graduation.pojo.query.CategoryQuery;
import com.graduation.pojo.vo.CategoryVO;
import com.graduation.service.CategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
@RequiredArgsConstructor
public class CategoryController {

    private final CategoryService categoryService;

    @GetMapping("/list")
    public List<CategoryVO> listCategories(CategoryQuery query) {
        return categoryService.listCategories(query);
    }

    @GetMapping("/{id}")
    public CategoryVO getCategoryById(@PathVariable("id") Long id) {
        return categoryService.getCategoryById(id);
    }

    @PostMapping
    public void saveCategory(@RequestBody Category category) {
        categoryService.saveCategory(category);
    }

    @PutMapping
    public void updateCategory(@RequestBody Category category) {
        categoryService.updateCategory(category);
    }

    @DeleteMapping("/{id}")
    public void deleteCategory(@PathVariable("id") Long id) {
        categoryService.deleteCategory(id);
    }

}
